const express = require('express');
const { routeWrapper } = require('../../../lib/module/tool/route');
const router = express.Router();
const promoteService = require('../../../lib/service/promoteService');

// 发送新用户红包
router.post('/dispatchEnvelope', routeWrapper(async (req, res, next) => {
    return promoteService.dispatchEnvelope(req.auth.userId);
}, true));

// 推广员授权客户
router.post('/authCustom/:customId', routeWrapper(async (req, res, next) => {
    return promoteService.authCustom(req.auth.userId, req.params.customId);
}, true));

// 绑定推广关系（生成推广记录）
router.post('/bindPromoteRelationship', routeWrapper(async (req, res, next) => {
    return promoteService.bindPromoteRelationship(req.body.promoterId, req.body.customId, req.body.areaId);
}, true));

// 查询我的推广二维码
router.get('/getPromoteQrcode', routeWrapper(async (req, res, next) => {
    return promoteService.getPromoteQrcode(req.auth.userId);
}, true));

// 查询我的推广信息总览
router.get('/getPromoteOverview', routeWrapper(async (req, res, next) => {
    return promoteService.getPromoteOverview(req.auth.userId);
}, true));

// 查询我推广的客户列表
router.get('/getPromoteRecord/:offset/:rows', routeWrapper(async (req, res, next) => {
    return promoteService.getPromoteRecord(req.auth.userId, req.query.beginTime, req.query.endTime,
        parseInt(req.params.offset), parseInt(req.params.rows));
}, true));

// 查询我推广的订单信息
router.get('/getPromoteOrderInfo/:offset/:rows', routeWrapper(async (req, res, next) => {
    return promoteService.getPromoteOrderInfo(req.auth.userId, req.query.beginTime, req.query.endTime,
        parseInt(req.params.offset), parseInt(req.params.rows), parseInt(req.query.status));
}, true));

module.exports = router;
